<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
    <style>
        #app{
            width: 500px;
        }
        table{
            width: 100%;
            border-collapse: collapse;
        }
        table tr th,table tr td{
height: 35px;
border-bottom: solid 1px #999;
text-align: center;
}
.clear-btn{
text-align: right;
}
    </style>
</head>
<body>
    <!-- 创造一个表单 -->
    <div id="app">
        <table>
            <tr >
                <th>编号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>操作</th>
            </tr>
            <tr v-for="(item,index) in user">
                <td>{{item.userId}}</td>
                <td>{{item.userName}}</td>
                <td>{{item.userAge}}</td>
                <td>
                    <input type="button" value="删除键" @click="dels(index)">
                </td>
            </tr>
            <tr>
                <td colspan="4"><input type="button" value="清空" @click="del"></td>
            </tr>
        
            
        </table>
        <h1>提交信息</h1>
        姓名：<input type="text" v-model="userName"><br>
        年龄：<input type="text" v-model="userAge"><br>
        <input type="button" value="提交" @click="sub">
        <script>
            let vm =new Vue({
                el:"#app",
                data(){
                    return {
                        user:[
                            {
                                userId:1,
                                userName:"张三",
                                userAge:18
                            },
                            {
                                userId:2,
                                userName:"张五",
                                userAge:31
                            },
                            {
                                userId:3,
                                userName:"张六",
                                userAge:99
                            },
                        

                        ],
                        userName:" ",
                        userAge:18
                    }
                },
                methods:{
                    del(){
                        this.user.splice(0,this.user.length)
                    },
                    sub(){
                        let userId=0
                        if (this.user.length==0) {
                            userId=1
                            
                        }else{
                            userId=this.user[this.user.length-1].userId+1
                        }
                        this.user.push({
                            userId:userId,
                            userName:this.userName,
                            userAge:this.userAge
                        })

                    },
                    dels(index){
                        this.user.splice(index,1)
                    }
                }
            })
        </script>
    </div>
</body>
</html>